# coding=utf-8
import random

from lib.Skill import EffectType


class Effect(object):
    def __init__(self, name, effect_type, target_self=False):
        super(Effect, self).__init__()
        self.name = name
        self.target_self = target_self
        self.effect_type = effect_type
        self.offset_val = self.offset_val()

    def target_is_friend(self):
        if self.is_buff() or self.effect_type is EffectType.HEAL or self.effect_type is EffectType.PHYSICAL_ARMOR or self.effect_type is EffectType.MAGIC_ARMOR:
            return True
        else:
            return False

    def is_round(self, effect_type):
        if effect_type == EffectType.DAMAGE or effect_type == EffectType.PHYSICAL_DAMAGE or EffectType.MAGIC_DAMAGE or EffectType.HEAL or EffectType.PHYSICAL_ARMOR or EffectType.MAGIC_ARMOR:
            return False
        else:
            return True

    def is_buff(self):
        if self.effect_type == EffectType.BUFF_DAMAGE \
                or self.effect_type == EffectType.BUFF_DAMAGE_PHYSICAL \
                or self.effect_type == EffectType.BUFF_DAMAGE_MAGIC \
                or self.effect_type == EffectType.BUFF_HEAL \
                or self.effect_type == EffectType.BUFF_OFFSET_HEAL \
                or self.effect_type == EffectType.BUFF_HEAL_PHYSICAL_ARMOR \
                or self.effect_type == EffectType.BUFF_HEAL_MAGIC_ARMOR \
                or self.effect_type == EffectType.BUFF_OFFSET_DAMAGE \
                or self.effect_type == EffectType.BUFF_OFFSET_PHYSICAL_DAMAGE \
                or self.effect_type == EffectType.BUFF_OFFSET_MAGIC_DAMAGE \
                or self.effect_type == EffectType.BUFF_VERTIGO \
                or self.effect_type == EffectType.BUFF_MOVE \
                or self.effect_type == EffectType.BUFF_BASE:
            return True
        else:
            return False

    def is_dot(self):
        if self.effect_type == EffectType.DOT_DAMAGE \
                or self.effect_type == EffectType.DOT_DAMAGE_PHYSICAL \
                or self.effect_type == EffectType.DOT_DAMAGE_MAGIC \
                or self.effect_type == EffectType.DOT_HEAL \
                or self.effect_type == EffectType.DOT_EASILY_DAMAGE \
                or self.effect_type == EffectType.DOT_EASILY_PHYSICAL_DAMAGE \
                or self.effect_type == EffectType.DOT_EASILY_MAGIC_DAMAGE \
                or self.effect_type == EffectType.DOT_VERTIGO \
                or self.effect_type == EffectType.DOT_MOVE \
                or self.effect_type == EffectType.DOT_BASE:
            return True
        else:
            return False

    # def is_scene(self):
    #     if self.effect_type == EffectType.BUFF_BASE \
    #             or self.effect_type == EffectType.SCENE_DAMAGE \
    #             or self.effect_type == EffectType.SCENE_DAMAGE_MAGIC \
    #             or self.effect_type == EffectType.SCENE_DAMAGE_PHYSICAL \
    #             or self.effect_type == EffectType.SCENE_HEAL \
    #             or self.effect_type == EffectType.SCENE_HEAL_MAGIC_ARMOR \
    #             or self.effect_type == EffectType.SCENE_HEAL_PHYSICAL_ARMOR \
    #             or self.effect_type == EffectType.SCENE_MOVE \
    #             or self.effect_type == EffectType.SCENE_VERTIGO:
    #         return True
    #     else:
    #         return False

    def targer_is_enemy(self):
        return not self.target_is_friend()

    def offset_val(self):
        return random.randint(0, 100)


class RoundEffect(Effect):
    def __init__(self, name, effect_type, target_self, round):
        super(RoundEffect, self).__init__(name, effect_type, target_self)
        self.round = round
        self.max_round = round

    def round_val(self, val=1):
        self.round -= val
